/**
 * Created by Administrator on 2017/8/25 0025.
 */


function queryUserName() {
    var name = $("#name").val();
    var account = $("#account").val();
    var created = $("#create").val();
    var obj = created.split("-");
    var startCreate = obj[0] + "-" + obj[1] + "-" + obj[2];
    if (obj[1] == undefined) {
        startCreate = "";
    }
    var endCreate = obj[3] + "-" + obj[4] + "-" + obj[5];
    if (obj[4] == undefined) {
        endCreate = "";
    }
    var url = $().AbsUrlParse("/web/score/queryHistoryGoodsScore?name=" + name + "&account=" + account + "&startCreate=" + startCreate + "&endCreate=" + endCreate);
    var table = $("#table");
    table.bootstrapTable("refresh", {url: url});
}

pic = function (value, row, index) {
    var img = row.listPic;
    var imgUrl = "";
    if (img != null && img != "") {
        imgUrl = File_Download_Url + img;
        return '<image src=' + imgUrl + ' style="width:80px;height:80px" onclick="enlargeImage(this)"/>';
    }
    if (img == null || img == "") {
        return '<image src=' + $().AbsUrlParse("/static/images/no.png") + ' style="width:80px;height:80px" onclick="enlargeImage(this)"/>'
    }
};


goodsName = function (value, row, index) {
    return [
        '<div style="width: 60%">' + row.goodsName + '</div>'
    ].join('')
};

sendGoods = function (value, row, index) {
    if (row.isSendGoods == 1) {
        return [
            '<div><span style="color:#3cc51f;">' + '已发货' + '</span></div> '
        ].join('');
    } else {
        return [
            '<div><a href="javascript:void(0);" class="sendGoods" >' + '未发货' + '</a></div> '
        ].join('');
    }
};

window.operateEvent = {
    'click .sendGoods': function (e, value, row, index) {
        comment.showOperationTips("确认发货？", function () {
            $.post($().AbsUrlParse('/web/score/updateIsSendGoods'), {
                id: row.id, sendGoods: 1
            }, function (data) {
                if (data.state == true) {
                    if (data.res.code == 40000) {
                        hint("发货成功");
                        var table = $("#table");
                        table.bootstrapTable("refresh");
                    } else {
                        hint(data.res.msg);
                    }
                } else {
                    hint(data.msg);
                }
            });
        });
    }
};


function initDateRange() {
    $(".rangedate").daterangepicker({
        "autoApply": true,
        "locale": {
            "applyLabel": "确定",
            "cancelLabel": "取消",
            "fromLabel": "开始",
            "toLabel": "结束",
            "customRangeLabel": "Custom",
            "weekLabel": "周",
            "daysOfWeek": [
                "日",
                "一",
                "二",
                "三",
                "四",
                "五",
                "六"
            ],
            "monthNames": [
                "1月",
                "2月",
                "3月",
                "4月",
                "5月",
                "6月",
                "7月",
                "8月",
                "9月",
                "10月",
                "11月",
                "12月"
            ],
            "cancelLabel": '清空',
            "opens": "right"
        },
        "format": "YYYY-MM-DD"
    }).on('cancel.daterangepicker', function (ev, picker) {
        $(this).val('');
    });
}

//初始化页面的时候运行该函数
$(function () {
    initDateRange();
});

function enlargeImage(value) {
    showModel("detailImage-div", function () {
        var imgs = '<image src=' + value.src + ' style="height:500px" />';
        $("#image").html(imgs);
    })
}